﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using MUD.Lib.Utils;

namespace MUD.Lib.Objects.Users
{
    /// <summary>
    /// An alias is a command shortcut. When the user enters a command that matches an alias,
    /// the alias substitutes its code for the command entered.
    /// </summary>
    internal class Alias
    {
        public string Command = "";
        public string Value = "";
        private string _allargs = "$*";

        public Alias(string cmd, string alias)
        {
            Command = cmd;
            Value = alias;
        }

        public string Translate(string command)
        {
            string retval = Value;
            if (command.NthWord(0) != Command)
                return null;

            if (retval.IndexOf(_allargs) > -1)
            {
                retval = retval.Replace(_allargs, command.Slice(1, null));
            }
            return retval.Trim();
        }
    }
}
